<%--
  Created by IntelliJ IDEA.
  User: TYZ
  Date: 2020/3/12
  Time: 19:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<div class="container-fluid">
    <div class="panel panel-primary" style="width:400px">
        <div class="panel-heading">
            <center><h1>注册</h1></center>
        </div>
        <div class="panel-body">
            <form id="registerForm">
                <div class="form-group">
                    <label for="username">请输入账号:</label>
                    <input type="text" class="form-control" name="username" placeholder="请输入账号">
                    <div id="tips"></div>
                </div>
                <div class="form-group">
                    <label for="upassword">请输入密码:</label>
                    <input type="password" class="form-control" name="upassword" placeholder="请输入密码">
                    <div id="tips"></div>
                </div>
                <div class="form-group">
                    <label for="lastname" class="col-sm-2 control-label">头像</label>
                    <div class="col-sm-10">
                        <input type="hidden" name="uimg" id="fileName">
                        <input type="file" id="myFile" name="myFile" multiple><!-- multiple支持多个文件上传 -->
                    </div>
                </div>
                <div class="form-group">
                    <label for="ubirthday">请输入生日:</label>
                    <input type="date" class="form-control" name="ubirthday" placeholder="请输入生日">
                    <div id="tips"></div>
                </div>
                <div class="form-group">
                    <label for="usex">请输入性别:</label>
                    <input type="radio" name="usex" value="1">男
                    <input type="radio" name="usex" value="2">女
                    <div id="tips"></div>
                </div>
                <button type="button" class="btn btn-info" onclick="registerInfo()">注册</button>
                <font color="red">已有账户???</font><a href="<%=path %>/index.jsp">去登陆</a>
            </form>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    function fileInit(){
        $('#myFile').fileinput({
            language: 'zh',
            uploadUrl: '<%=path%>/file/upLoadFile',
            maxFileCount :3, // 最多同时传送几个图片，需要加multiple注解
            enctype : 'multipart/form-data',
            maxFileSize : 1024, //单位为kb
            allowedFileExtensions : ['jpg', 'gif', 'png'],
            browseClass: 'btn btn-primary'
        });

        $('#myFile').on('fileuploaded',function(event, data, previewId, index){
            $("#fileName").val(data.response.imgUrl);
        })
    }

    $(function(){
        fileInit();
    })

    function registerInfo(){
        $.ajax({
            url:"<%=path %>/userController/registerInfo",
            type:"post",
            dataType:"json",
            data:$("#registerForm").serialize(),
            async:true,
            success:function(result){
                if (result == 1) {
                    alert("该账户已被注册,换个试试````````");
                }else if(result == 2){
                    alert("注册成功,请登录");
                    location.href="<%=path %>/index.jsp";
                }
            },
            error:function(result){
                alert("系统异常,请联系管理员");
            }
        })
    }
</script>
</html>
